Apollo|Stateful Links

Stateful Links

某些 Link 需要在请求之间共享 state,从而完成额外的功能.
Stateful links 总是重写ApolloLink

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { ApolloLink } from 'apollo-link';

class OperationCountLink extends ApolloLink {
constructor() {
super();
this.operations = 0;
}
request(operation, forward) {
this.operations++
return forward(operation);
}
}

const link = new OperationCountLink();